﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Framework.Mvc.Util
{
    public class SuccessJsonpResult : JsonpResult
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="success"></param>
        /// <param name="msg"></param>
        /// <param name="obj"></param>
        public SuccessJsonpResult(bool success, string msg = null, object obj = null)
            : this(success ? 1 : 0, msg, obj)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        public SuccessJsonpResult(int code, string msg = null, object obj = null)
        {
            if (msg.IsBlank())
            {
                msg = "操作" + (code > 0 ? "成功" : "失败");
            }
            Data = new SuccessStatusObject
            {
                code = code,
                message = msg,
                data = obj
            };
            JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet;
        }

        /// <summary>
        /// Success Status Object
        /// </summary>
        public class SuccessStatusObject
        {
            public int code { get; set; }
            public string message { get; set; }
            public object data { get; set; }
        }
    }
}
